package com.android.hedgehog;

import java.util.List;

import android.graphics.Color;

import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Screen;
import com.android.hedgehog.framework.Input.TouchEvent;

public class MainMenu2 extends Screen {
	Graphics graphics;
	MainMenuBackground background;
	int yPos = 0;

	public MainMenu2(Game game) {
		super(game);
		graphics = game.getGraphics();
		background = new MainMenuBackground();
	}

	@Override
	public void update(float deltaTime) {
		yPos++;
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		int len = touchEvents.size();

		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {
				if (event.x > 110 && event.x < 210 && event.y > 210 && event.y < 260) {
					game.setScreen(new LevelSelect(game));
					playSound(1);
				}
				if (event.x > 40 && event.x < 140 && event.y > 270 && event.y < 320) {
					game.setScreen(new Records(game));
					playSound(1);
				}
				if (event.x > 180 && event.x < 280 && event.y > 270 && event.y < 320) {
					game.setScreen(new FreePlayMenu2(game));
					playSound(1);
				}
				if (event.x > 40 && event.x < 140 && event.y > 340 && event.y < 390) {
					//game.setScreen(new LockBufferScreen(game));
					//Settings.round--;//test
					playSound(1);
				}
				if (event.x > 180 && event.x < 280 && event.y > 340 && event.y < 390) {
					//Settings.round++;//test
					playSound(1);
				}

				if (event.x < 40 && event.y > 440) {
					Settings.soundEnabled = !Settings.soundEnabled;
					Assets.click.play(5);
				}
			}
		}

	}

	private void playSound(int soundNum) {
		if (!Settings.soundEnabled)
			return;
		if (soundNum == 1)
			Assets.bitten.play(1);

	}

	@Override
	public void present(float deltaTime) {
		graphics.drawBackground(Color.BLACK);

		for (int i = 0; i < 80; i++) {
			graphics.drawText(background.matrix[i], 160, ((yPos + (i * 6)) % 480), 6, Color.GREEN);
		}

		graphics.drawSpecialText("CYBER", 158, 93, 88, 2, Color.GRAY);
		graphics.drawSpecialText("IQ", 158, 172, 94, 2, Color.GRAY);
		graphics.drawSpecialText("CYBER", 160, 95, 88, 2, Color.GREEN);
		graphics.drawSpecialText("IQ", 160, 174, 94, 2, Color.GREEN);
		graphics.drawSpecialText("DEMO version", 160, 188, 12, 1, Color.RED);

		graphics.drawUniversalRect(110, 210, 100, 50, true, true, 1, 255, Color.BLACK);
		graphics.drawUniversalRect(110, 210, 100, 50, true, false, 5, 255, Color.YELLOW);
		graphics.drawUniversalText("VERSES", 1, true, 160, 242, 18, 255, Color.YELLOW);

		graphics.drawUniversalRect(40, 270, 100, 50, true, true, 1, 255, Color.BLACK);
		graphics.drawUniversalRect(40, 270, 100, 50, true, false, 5, 255, Color.BLUE);
		graphics.drawUniversalText("RECORDS", 1, true, 90, 302, 18, 255, Color.BLUE);

		graphics.drawUniversalRect(180, 270, 100, 50, true, true, 1, 255, Color.BLACK);
		graphics.drawUniversalRect(180, 270, 100, 50, true, false, 5, 255, Color.RED);
		graphics.drawUniversalText("FREEPLAY", 1, true, 230, 302, 18, 255, Color.RED);

		graphics.drawUniversalRect(40, 340, 100, 50, true, true, 1, 255, Color.BLACK);
		graphics.drawUniversalRect(40, 340, 100, 50, true, false, 5, 255,
				Color.argb(255, 238, 106, 167));
		graphics.drawUniversalText("SETTINGS", 1, true, 90, 372, 18, 255,
				Color.argb(255, 238, 106, 167));

		graphics.drawUniversalRect(180, 340, 100, 50, true, true, 1, 255, Color.BLACK);
		graphics.drawUniversalRect(180, 340, 100, 50, true, false, 5, 255, Color.GRAY);
		graphics.drawUniversalText("OTHER", 1, true, 230, 372, 18, 255, Color.GRAY);

		if (Settings.soundEnabled)
			graphics.drawPixmap(Assets.buttons40, 0, 440, 0, 0, 40, 40);
		else
			graphics.drawPixmap(Assets.buttons40, 0, 440, 40, 0, 40, 40);

	}

	@Override
	public void pause() {
		Settings.round=1; //test
		Settings.save(game.getFileIO());

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
